home *** CD-ROM | disk | FTP | other *** search
/ C# & Game Programming - A…er's Guide (2nd Edition) / Buono 2nd Ed.iso / Chapter2 / 2.29 / 2.29.cs next >
Text File  |  2004-08-31  |  5KB  |  89 lines

  1. /* Battle Bit II û THIS IS WAR! Some mad dog soldier shot down the 
  2.  * alien Ambassador's convoy and it sparked an intergalactic war. 
  3.  * Earth's defenses was weak form warring with several hundred other
  4.  * worlds. So now, it's all up to you. */ 
  5. using System;
  6.  
  7. namespace Chapter2 {
  8.     class Class1 {
  9.         static void Main() {
  10.             string input;
  11.             char cYesNo;  
  12.       
  13.             Random rnd = new Random();
  14.     
  15.             do { // do-while loop
  16.                 double iAlienShip1 = Math.Round (rnd.NextDouble() * 100) + 1,  
  17.                     iAlienShip2 = Math.Round (rnd.NextDouble() * 100) + 1,
  18.                     iTarget = 0,                            
  19.                     iAliensMissiles = 0;               
  20.                 const double iYourLocation = 50;        
  21.       
  22.                 Console.WriteLine("Captain, are you in there? Captain?\n" 
  23.                     + "(Crying is herd form his quarters)\n" 
  24.                     + "This is ground control to lieutenant Bob.\n" 
  25.                     + "Your brother Major Tom has been shot down,\n"  
  26.                     + "Repeat he has been shot down.\n" 
  27.                     + "The aliens have destroyed our space outpost and \n"
  28.                     + "are now on route to Earth.\n" 
  29.                     + "I know it's a long shot Lieutenant,\n"  
  30.                     + "but I promised my wife and kids you'd  stop them.\n" 
  31.                     + "I'll do my best...\n");  
  32.      
  33.                 while ((iAlienShip1 > 0) || (iAlienShip2 > 0)) {
  34.                     Console.Write("\n\n Enter targeting information: ");     
  35.                     input = Console.ReadLine();
  36.                     iTarget = byte.Parse(input); 
  37.           
  38.                     Console.WriteLine("{0},{1}", iAlienShip1, iAlienShip2);
  39.          
  40.                     if (Math.Ceiling(iTarget) == Math.Ceiling(iAlienShip1)
  41.                             || Math.Ceiling(iTarget) == Math.Floor(iAlienShip1)
  42.                             || Math.Floor(iTarget) == Math.Ceiling(iAlienShip1)
  43.                             || Math.Floor(iTarget) == Math.Floor(iAlienShip1)) {
  44.                         Console.WriteLine("Alien ship hit, you got him!");
  45.                         iAlienShip1 = -1; 
  46.                     }                 
  47.         
  48.                     if (Math.Ceiling(iTarget) == Math.Ceiling(iAlienShip2)
  49.                             || Math.Ceiling(iTarget) == Math.Floor(iAlienShip2)
  50.                             || Math.Floor(iTarget) == Math.Ceiling(iAlienShip2)
  51.                             || Math.Floor(iTarget) == Math.Floor(iAlienShip2)) {
  52.                         Console.WriteLine("\nAlien ship hit, you took him down!!\n");
  53.                         iAlienShip2 = -1; 
  54.                     }                 
  55.         
  56.                     if ((Math.Round (iTarget) > Math.Round (iAlienShip1))
  57.                             && (Math.Round (iTarget) > Math.Round (iAlienShip2)))  
  58.                         Console.WriteLine("\n You missed, try aiming a little lower\n");
  59.                     else if ((iTarget < iAlienShip1) && (iTarget < iAlienShip2))   
  60.                         Console.WriteLine("\n You missed, try aiming higher\n");
  61.                     else
  62.                         Console.WriteLine("\n I can't get a lock on them\n");
  63.           
  64.                     if (Math.Ceiling(iAliensMissiles) == Math.Ceiling(iYourLocation)
  65.                             || Math.Ceiling(iAliensMissiles) == Math.Floor(iYourLocation)
  66.                             || Math.Floor(iAliensMissiles) == Math.Ceiling(iYourLocation)
  67.                             || Math.Floor(iAliensMissiles) == Math.Ceiling(iYourLocation))
  68.                         break; 
  69.                     else
  70.                         iAliensMissiles = rnd.NextDouble();  
  71.                 } // end loop                                                           
  72.      
  73.                 if ((iAlienShip1 + iAlienShip2) < 0)                                                 
  74.                     Console.WriteLine("\n Good work lieutenant, " 
  75.                         + "or should I say captain.\n");
  76.                 else                                                                
  77.                     Console.WriteLine("\n BOOM!!! You're dead.\n");         
  78.            
  79.                 Console.WriteLine("\n Game Over\n" 
  80.                     + "\n Would you like to play again? (Y/N)");
  81.                 input = Console.ReadLine();
  82.                 cYesNo = char.Parse(input);
  83.                 cYesNo = char.ToUpper(cYesNo);
  84.             } while (cYesNo == 'Y');   
  85.         } 
  86.     } 
  87. }
  88.  
  89.